package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.doubleedged;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.UUID;

public class GlassSkill extends BaseSkill {

    public static UUID uuid = UUID.fromString("5C87EBCA-BB83-4897-9A40-03D53D6BD860");

    public GlassSkill(int level) {
        super(level);
    }

    public GlassSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public GlassSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(1);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return "玻璃技能，5倍伤害，也会受到5倍伤害。";
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.DoubleEdged;
    }

    @Override
    public boolean passiveApply(MobEntity mobEntity) {
        EntityAttributeModifier modifier = new EntityAttributeModifier(uuid, getName(), mobEntity.getMaxHealth() * 0.2, EntityAttributeModifier.Operation.fromId(0));
        EntityAttributeInstance entityAttributeInstance = mobEntity.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
        if (entityAttributeInstance == null) return true;
        if (!entityAttributeInstance.hasModifier(modifier))
            entityAttributeInstance.addPersistentModifier(modifier);
        return true;
    }

    @Override
    public boolean onAttack(MobEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        amount.setValue(amount.getValue() * 5);
        return true;
    }
}
